package baidu.reader.common.effects
{
    import baidu.reader.common.model.*;
    import baidu.ui.managers.*;
    import flash.display.*;
    import flash.events.*;

    public class PageTurnManager extends EventDispatcher
    {
        private var stage:Stage;

        public function PageTurnManager(param1:IEventDispatcher = null)
        {
            super(param1);
            this.stage = (InstanceManager.createSingletonInstance(ScreenModel) as ScreenModel).stage;
            return;
        }

        public function startSingleTurn(param1:DisplayObject, param2:Boolean = true, param3:int = 1) : void
        {
            var _loc_4:* =  new PageFlip();
			_loc_4.width = param1.width * 2;
            _loc_4.height = param1.height;
            this.stage.addChild(_loc_4);
            _loc_4.x = (-_loc_4.width) / 2 + param1.x;
            _loc_4.y = param1.y;
            if (param2)
            {
                _loc_4.startEffect2(param1, false, true);
            }
            else
            {
                _loc_4.startEffect2(param1, true, true);
                _loc_4.addEventListener(PageEffectEvent.EFFECT_END, this.onEffectEnd, false, 0, true);
            }
            return;
        }

        public function startDoublePageTurn(param1:DisplayObject, param2:Boolean = true, param3:int = 1) : void
        {
            var _loc_4: PageFlip = new PageFlip();
			_loc_4.width = param1.width;
            _loc_4.height = param1.height;
            this.stage.addChild(_loc_4);
            _loc_4.x = param1.x;
            _loc_4.y = param1.y;
            if (param2)
            {
                _loc_4.startEffect(param1, false, false);
                _loc_4.addEventListener(PageEffectEvent.EFFECT_END, this.onEffectEnd, false, 0, true);
            }
            else
            {
                _loc_4.startEffect(param1, true, false);
                _loc_4.addEventListener(PageEffectEvent.EFFECT_END, this.onEffectEnd, false, 0, true);
            }
            return;
        }

        private function onEffectEnd(event:Event) : void
        {
            dispatchEvent(new PageEffectEvent(PageEffectEvent.EFFECT_END));
            return;
        }

        public static function getInstance() : PageTurnManager
        {
            return InstanceManager.createSingletonInstance(PageTurnManager);
        }

    }
}
